/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.gatech.ealf.ttsplaf;

import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JComponent;
import javax.swing.event.ChangeEvent;
import javax.swing.plaf.SliderUI;
import javax.swing.plaf.ComponentUI;

import javax.swing.JSlider;
import javax.swing.event.ChangeListener;
/**
 *
 * @author hemanthpai
 */
public class TTSSliderUI extends SliderUI implements MouseListener, ChangeListener{
    
    private TTSHelper helper = null;
    
    public TTSSliderUI(){
        super();
    }
    
     @Override
    public void installUI(JComponent c) {
    	super.installUI(c);
        TextToSpeechLookAndFeel.getInstance().registerComponentInstallation(this, c);
        helper = TTSHelper.getInstance();
        JSlider s = (JSlider)c;
        helper.readConfig(s);
        s.addMouseListener(this);
        s.addChangeListener(this);
    }
    
    @Override
    public void uninstallUI(JComponent c) {
    	super.uninstallUI(c);
        TextToSpeechLookAndFeel.getInstance().registerComponentUninstallation(this, c);
        JSlider s = (JSlider)c;
        s.removeMouseListener(this);
        s.removeChangeListener(this);
    }
    
    @Override
    public void paint(Graphics g, JComponent c) {
       
    }
     
    @Override
    public void update(Graphics g, JComponent c) {
        
    }
     
    public static ComponentUI createUI(JComponent c) {
        return new TTSSliderUI();
    }
    

    public void mouseClicked(MouseEvent e) {
         if(e.getButton()== MouseEvent.BUTTON2){
            helper.toggleSpeak();
        }
    }

    public void mousePressed(MouseEvent e) {
        
    }

    public void mouseReleased(MouseEvent e) {
       
    }

    public void mouseEntered(MouseEvent e) {
        helper.mouseEntered(e);
    }

    public void mouseExited(MouseEvent e) {
        
    }

    public void stateChanged(ChangeEvent e) {
        helper.stateChanged(e);
    }

}
